﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.DBM; 

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class DC_CommandDiscipline : System.Web.UI.UserControl
    {
        private SsMng ssMng = new SsMng();
        private object _dataItem = null;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }

  
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);
       
            if (!IsUserControlPostBack)
            {

                BindComboEmpType();
                BindComboInvestigation();
                BindComboPenaltyLevel();
                BindComboCrimeDtls();
                BindRadio();
                this.ViewState.Add("IsUserControlPostBack", true);

            }



            if (DataItem != null)
            {
                //   cbGender.ListGenderComboBox();

     
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
               //     BindRadio2();
               //     lblPenSeq.Text   = DataBinder.Eval(DataItem, "cr_seq").ToString();

               //     radStatus.SelectedValue = DataBinder.Eval(DataItem, "record_status").ToString();

               ////     txtName.Text = DataBinder.Eval(DataItem, "cr_name").ToString(); 
        
             
                }


             

                btnUpdate.Visible = !(DataItem is Telerik.Web.UI.GridInsertionObject);
                btnAddnew.Visible = (DataItem is Telerik.Web.UI.GridInsertionObject);
            }


       
      
        }


        private void BindRadio()
        {
            CrimesBLL obj = new CrimesBLL();
            DataTable dt;
            dt = obj.SelectStatus();

            if (dt != null && dt.Rows.Count > 0)
            {
             
                //foreach (DataRow cur in dt.Rows)
                //{
                //    ListItem Li = new ListItem();
                //    Li.Text = cur["record_status_name"].ToString();// + " " + ((DateTime)cur["act_start_date"]).ToString("dd/MM/yyyy", new CultureInfo("th-TH")) + " ถึง " + ((DateTime)cur["act_end_date"]).ToString("dd/MM/yyyy", new CultureInfo("th-TH"));
                //    Li.Value = cur["record_status"].ToString();
                //    radStatus.Items.Add(Li);
                //}

                //radStatus.DataBind();
                //radStatus.SelectedIndex = 1;
            }
            else
            {
              //  radStatus.Items.Clear();
            }




        }

        private void BindRadio2()
        {
            CrimesBLL obj = new CrimesBLL();
            DataTable dt;
            dt = obj.SelectStatus();

            if (dt != null && dt.Rows.Count > 0)
            {
                //radStatus.Items.Clear();
                //radStatus.DataSource = dt;
                //radStatus.DataTextField = "record_status_name";
                //radStatus.DataValueField = "record_status";
                //foreach (DataRow cur in dt.Rows)
                //{
                //    ListItem Li = new ListItem();
                //    Li.Text = cur["record_status_name"].ToString();// + " " + ((DateTime)cur["act_start_date"]).ToString("dd/MM/yyyy", new CultureInfo("th-TH")) + " ถึง " + ((DateTime)cur["act_end_date"]).ToString("dd/MM/yyyy", new CultureInfo("th-TH"));
                //    Li.Value = cur["record_status"].ToString();
                //    radStatus.Items.Add(Li);
                //}

              //  radStatus.DataBind();
      
            }
            else
            {
              //  radStatus.Items.Clear();
            }




        }



        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
        protected void btnAddnew_Click(object sender, EventArgs e)
        {

         
 
        }


        protected void btnUpdate_Click(object sender, EventArgs e)
        {

     



        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }




        private IEmployeeBLL empBLL = new EmployeeBLL();

        protected void btnFindEmp_Click(object sender, ImageClickEventArgs e)
        {


            string st = Hide.Value;
            //if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
            //    st = DataBinder.Eval(DataItem, "req_seq").ToString();
            EmployeeInfo infoEmp;
            IList<EmployeeInfo> infoList = empBLL.ListEmployees(st);
            infoEmp = infoList[0];


            // infoEmp.Class.Sequence != null

          lblEmpSeq.Text = infoEmp.Sequence.ToString();
            lblPosName.Text = lblPosName.Text = infoEmp.Position.Name != null ? infoEmp.Position.Name.ToString() : "";
            lblClassName.Text = infoEmp.Class.Name != null ? infoEmp.Class.Name.ToString() : "";
            lblJobsiteName.Text = infoEmp.WorkingJobSite.Name != null ? infoEmp.WorkingJobSite.Name.ToString() : "";
            lblSalary.Text = infoEmp.Salary != null ? infoEmp.Salary.ToString() : "";      

            lblPosRef.Text = infoEmp.Position.RefNo != null ? infoEmp.Position.RefNo.ToString() : "";
            txtEmp.Text = infoEmp.Person.FirstName.ToString() + "   " + infoEmp.Person.LastName.ToString();


        }


        private void BindComboInvestigation()
        {
            CommandDisciplineBLL obj = new CommandDisciplineBLL();
  DataTable dt;
  dt = obj.SelectInvestigationCombo();



  ComboInvestigation.DataValueField = "inv_seq";
  ComboInvestigation.DataTextField = "inv_name";

  ComboInvestigation.DataSource = dt;
  ComboInvestigation.DataBind(); 

        }

        private void BindComboPenaltyLevel()
        {
            CommandDisciplineBLL obj = new CommandDisciplineBLL();
            DataTable dt;
            dt = obj.SelectPenaltyLevelCombo();



            ComboPenaltyLevel.DataValueField = "pen_level_seq";
            ComboPenaltyLevel.DataTextField = "pen_level_name";

            ComboPenaltyLevel.DataSource = dt;
            ComboPenaltyLevel.DataBind();

        }



        private void BindComboCrimeDtls()
        {
            CommandDisciplineBLL obj = new CommandDisciplineBLL();
            DataTable dt;
            dt = obj.SelectCrimeDtlsCombo(); 



            ComboCrimeDtls.DataValueField = "crd_seq";
            ComboCrimeDtls.DataTextField = "crd_name";

            ComboCrimeDtls.DataSource = dt;
            ComboCrimeDtls.DataBind();

        }


        private void BindComboEmpType()
        {
            CommandDisciplineBLL obj = new CommandDisciplineBLL();
            DataTable dt;
            dt = obj.SelectEmpTypeCombo();

            ComboEmpType.DataValueField = "emp_type_seq";
            ComboEmpType.DataTextField = "emp_type_name";

            ComboEmpType.DataSource = dt;
            ComboEmpType.DataBind();

        }



        protected void btnFindEmp_Load(object sender, EventArgs e)
        {

            if (DataItem is Telerik.Web.UI.GridInsertionObject)
            {



                string ETID;// = ssMng.EmpSeq ;

                ETID = "0";
                //   btnFindEmp.Attributes.Add("OnClick", "LinkMDdetail(" + Hide.ClientID + "," + "'Forms/DialogEmp.aspx?ETID=" + ETID + "&JSID=1','../frmIframe.html',700,500)");
                btnFindEmp.Attributes.Add("OnClick", "LinkMDdetail(" + Hide.ClientID + "," + "'Forms/DialogDisciplineCommand.aspx?ETID=" + ETID + "','../frmIframe.html',700,500)");
            }

        }

        protected void ComboEmpType_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {

            Session["EmpType"] = ComboEmpType.SelectedValue; 


        }
    }
}